#!/usr/bin/perl
#
use strict;
use warnings;
use Data::Dumper;
 
binmode STDOUT, ":utf8";
#use utf8;
 
use JSON;

require "doa_subs.pl";

############################## Main Prog ##############################

my $player_id={};
my $player_name={};

loadPlayers($player_id,$player_name);
my @actFiles=readDir("dump");
#print Dumper(@actFiles);
foreach my $actfile (@actFiles)
{
	print "Processing $actfile\n";
	my $fullname="dump/".$actfile;
	my $data=readJSON($fullname);
	my $actarray=[];
	$actarray = $data->{'activity'} if exists $data->{'activity'};
	$actarray = $data->{'dynamic'}{'players'}{'activity'} if exists $data->{'dynamic'}{'players'}{'activity'};
	if (ref($actarray) eq 'ARRAY')
	{
		foreach my $actref (@$actarray)
		{
	#		print "$actref->{'pname'} $actref->{'aname'}\n";
	#		$player_id->{$actref->{'id'}}=$actref->{'aname'} if exists $actref->{'id'};
			$player_id->{$actref->{'pid'}}=$actref->{'pname'} if exists $actref->{'pid'};
			$player_id->{$actref->{'aid'}}=$actref->{'aname'} if exists $actref->{'aid'};
		}
	}
	#my $playerdata = $data->{'map'}{'players'} if exists $data->{'map'}{'players'};
	#foreach my $id (keys %{$playerdata})
	#{
 		#my $plref=$playerdata->{$id};
		#foreach my $actref (@$plref)
		#{
##			print Dumper($actref);
			#$player_id->{$id}=$actref if $actref ne "0";
		#}
	#}
}
writePlayers($player_id);



